import 'package:flutter/cupertino.dart';
import 'package:flutter_pickers/more_pickers/route/single_picker_route.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:flutter_pickers/pickers.dart';
import 'package:flutter_pickers/style/picker_style.dart';

void singlePicker(
  BuildContext context, {
  bool? showTitleBar,
  Widget? menu,
  double? pickerHeight,
  double? pickerTitleHeight,
  double? pickerItemHeight,
  double? menuHeight,
  Widget? cancelButton,
  Widget? commitButton,
  Widget? title,
  Decoration? headDecoration,
  Color? backgroundColor,
  Color? textColor,
  double? textSize,
  Widget? itemOverlay,
  String? suffix,
  SingleCallback? onConfirm,
  SingleCallback? onChanged,
  Function(bool isCancel)? onCancel,
  required List data,
  required dynamic selectData,
}) {
  double menuHeight = 36.0;

  var pickerStyle = PickerStyle(
    menu: menu,
    menuHeight: menuHeight,
    cancelButton: cancelButton ??
        Container(
          padding: EdgeInsets.symmetric(horizontal: 24.w, vertical: 8.w),
          child: Text(MultiLanguage.cancel.tr, style: normalTextColor28),
        ),
    commitButton: commitButton ??
        Container(
          padding: EdgeInsets.symmetric(horizontal: 24.w, vertical: 8.w),
          child: Text(MultiLanguage.determine.tr, style: primaryTextColor28),
        ),
    textSize: textSize ?? 36.sp,
    headDecoration: headDecoration ??
        BoxDecoration(
            color: ThemeUtil.getTheme().colorScheme.secondary,
            borderRadius:
                const BorderRadius.only(topLeft: Radius.circular(8), topRight: Radius.circular(8))),
    title: title,
    textColor: textColor ?? ThemeUtil.getTheme().primaryColor,
    backgroundColor: ThemeUtil.getTheme().colorScheme.secondary,
    itemOverlay: itemOverlay ??
        CupertinoPickerDefaultSelectionOverlay(
            background: ThemeUtil.getTheme().normalTextColor().withOpacity(0.1)),
  );

  Pickers.showSinglePicker(
    context,
    data: data,
    selectData: selectData,
    suffix: suffix,
    pickerStyle: pickerStyle,
    onConfirm: onConfirm,
    onChanged: onChanged,
    onCancel: onCancel,
  );
}
